//MAX-SAT GA problem-depended class
//$Id: maxsat_ga.h 441 2010-04-09 17:27:20Z Oleg.Bulychov $
#pragma once

#include "projects/maxsat/maxsat.h"
#include "solvers/ga/ga_common.h"

//__________________________________________________________________________________
template<>
struct solution<MaxSat_Solution, ga_tag>:
    public MaxSat_Solution
{
    typedef solution<MaxSat_Solution, ga_tag> MaxSat_Solution_GA;
public:
    mutable double wheel_sector_;

    template<class E>
    void cross(E* env, uniform_random& rnd, MaxSat_Solution_GA& genome)
    {//:simple one point crossover
        ASSERT_(data_.size());
        ASSERT_(data_.size() == genome.data_.size());
        size_t size = data_.size();
        size_t j = rnd.next_SizeT(size);
        for (size_t i = j; i < size; ++i)
        {
            std::swap(data_[i], genome.data_[i]);
        }
        changed_ = genome.changed_ = true;
    }

    template<class E>
    void mutate(E* env, uniform_random& rnd, double mutationProbability)
    {
        for (size_t i = 0; i < data_.size(); ++i)
        {
            if (rnd.next_Double() < mutationProbability)
            {
                data_[i] = !data_[i];
                changed_ = true;
            }
        }
    }

    int get_Fitness() const { return get_Cost(); }
};
//__________________________________________________________________________________

//EOF!
